﻿Public Class FormCurrent
    Public usr As String
    Dim objProdInfo As New clsProdInfo
    Private Sub FormCurrent_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        setDgvData()
    End Sub
    Private Sub setDgvData()
        Dim dt As DataTable = objProdInfo.getLHList()
        dgv.Font = New Font("UTF-8", 12)
        If dt.Rows.Count > 0 Then
            For Each row As DataRow In dt.Rows
                If DBNull.Value.Equals(row("into_vu_time")) = False And DBNull.Value.Equals(row("lh_total_duration")) = False Then
                    Dim temp_time_length As Double = Double.Parse(row("lh_total_duration"))
                    'Double.Parse(row("time_length_1")) + Double.Parse(row("time_length_2")) + Double.Parse(row("time_length_3"))
                    row("comp_time") = DateTime.Parse(row("into_vu_time")).AddMinutes(temp_time_length).ToString()
                End If
            Next
        End If
        Dim dv As DataView = dt.DefaultView
        dv.Sort = " comp_time Asc"
        Dim dtnew As DataTable = dv.ToTable()
        dgv.AutoGenerateColumns = False
        dgv.DataSource = dtnew
    End Sub

    Private Sub btnAbnormalAdd_Click(sender As Object, e As EventArgs) Handles btnAbnormalAdd.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim formLhAbnormalAdd As New FormLhAbnormalAdd()
            formLhAbnormalAdd.prod_id = dgv.SelectedRows(0).Cells("prod_id").Value.ToString()
            formLhAbnormalAdd.lhj_id = dgv.SelectedRows(0).Cells("lhj_id").Value.ToString()
            formLhAbnormalAdd.steel_seal_no = dgv.SelectedRows(0).Cells("steel_seal_no").Value.ToString()
            formLhAbnormalAdd.usr = usr
            formLhAbnormalAdd.ShowDialog(Me)
        End If
    End Sub

    Private Sub rbOK_CheckedChanged(sender As Object, e As EventArgs) Handles rbOK.CheckedChanged
        If dgv.SelectedRows.Count > 0 Then
            If rbOK.Checked Then
                objProdInfo.yjStatus(dgv.SelectedRows(0).Cells("prod_id").Value.ToString(), rbOK.Text)
            End If
        End If
    End Sub

    Private Sub rbNG_CheckedChanged(sender As Object, e As EventArgs) Handles rbNG.CheckedChanged
        If dgv.SelectedRows.Count > 0 Then
            If rbNG.Checked Then
                objProdInfo.yjStatus(dgv.SelectedRows(0).Cells("prod_id").Value.ToString(), rbNG.Text)
            End If
        End If
    End Sub

    Private Sub dgv_SelectionChanged(sender As Object, e As EventArgs) Handles dgv.SelectionChanged
        If dgv.SelectedRows.Count > 0 Then
            Dim dtpi As DataTable = objProdInfo.getyjStatus(dgv.SelectedRows(0).Cells("prod_id").Value.ToString())
            If dtpi.Rows(0)("yj_status").ToString().Equals("未检查") Then
                rbOK.Checked = False
                rbNG.Checked = False
            Else
                If dtpi.Rows(0)("yj_status").ToString().Equals(rbOK.Text) Then
                    rbOK.Checked = True
                End If
                If dtpi.Rows(0)("yj_status").ToString().Equals(rbNG.Text) Then
                    rbNG.Checked = True
                End If
            End If
        End If
    End Sub
End Class